package com.basemanage.controller.artical;

import java.util.HashSet;
import java.util.Set;

import com.basemanage.core.controller.JCBaseController;
import com.basemanage.core.model.Condition;
import com.basemanage.core.model.Operators;
import com.basemanage.core.util.CommonUtils;
import com.basemanage.core.util.JqGridModelUtils;
import com.basemanage.core.view.InvokeResult;
import com.basemanage.model.SmNewstype;
import com.basemanage.service.newstypeService;
import com.jfinal.plugin.activerecord.Page;

public class newstypeController extends JCBaseController {
	
	public void index() {
		render("newstype_index.html");
	}
	
	/**
	 * 跳转（添加/编辑）页面
	 */
	public void addnewstype(){
		Integer id=getParaToInt("id");
		String action="add";
		if(id!=null){
			this.setAttr("item", SmNewstype.dao.findById(id));
			action="edit";
		}
		this.setAttr("action", action);
		render("newstype_add.html");
	}
	
	
	/**
	 * 数据分页列表
	 */
	public void getListData() {
		
		String name=this.getPara("name");
		Set<Condition> conditions=new HashSet<Condition>();
		if(CommonUtils.isNotEmpty(name)){
			conditions.add(new Condition("remark",Operators.LIKE,name));
		}
		
		Page<SmNewstype> pageInfo=SmNewstype.dao.getPage(this.getPage(), this.getRows(),conditions,this.getOrderby());
		this.renderJson(JqGridModelUtils.toJqGridView(pageInfo)); 
	}
	
	/**
	 * 保存数据
	 */
	public void savenewstype(){
		SmNewstype newstype=getModel(SmNewstype.class,"obj");
		InvokeResult result=newstypeService.me.savenewstype(newstype);
		this.renderJson(result);
	}
	 
	/**
	 * 删除数据
	 */
	public void delnewstype(){
		String ids=this.getPara("ids");
		InvokeResult result=newstypeService.me.delnewstype(ids);
		this.renderJson(result);
	}
	
}